// pages/farmerend/saledetails/saledetails.js
var utils = require('../../../utils/util.js');
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ishide: true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        that.setData({
            id: options.id
        })
        that.delivery();
    },
    onShow: function() {
        var that = this;
        that.onOrderList(that.data.id);
    },
    //快递公司

    delivery: function(e) {
        var that = this;
        utils.http("/api/v1/common/get_all_delivery", {}, function(res) {
            that.setData({
                array: res.datas
            })
        })
    },
    onOrderList: function(id) {
        var that = this;
        utils.showLoading();
        utils.http("/api/v1/order/my_order_detail", {
            order_id: id
        }, function(res) {
            utils.hideLoading();
            that.setData({
                info: res.datas,
            })
        })
    },
    //关闭弹窗
    closeTap: function(e) {
        var that = this;
        that.setData({
            ishide: true
        })
    },

    //打开弹窗
    onColseOrderTap: function(e) {
        var that = this;
        that.setData({
            ishide: false
        })
    },
    //获取输入内容快递单号
    bindInputTap: function(e) {
        var that = this;
        that.setData({
            logistics: e.detail.value
        })
    },
    bindPickerChange(e) {
        this.setData({
            index: e.detail.value,
            delivery_id: this.data.array[e.detail.value].id
        })
        console.log('picker发送选择改变，携带值为', this.data.delivery_name)
    },

    //扫描快递单号
    salescanCode: function(e) {
        var that = this;
        wx.scanCode({
            success(res) {
                that.setData({
                    logistics: res.result
                })
                console.log(that.data.logistics)
            }
        })
    },
    butareaHover: function(e) {
        var that = this;
        utils.showLoading();
        if (that.data.delivery_id != undefined && that.data.logistics != undefined) {
            utils.http("/api/v1/storemanage/nong_order_deliver", {
                order_id: that.data.id,
                logistics: that.data.logistics,
                delivery_id: that.data.delivery_id,
                store_id: app.globalData.id
            }, function(res) {
                utils.hideLoading();
                console.log(res);
                that.setData({
                    ishide: true
                })
                that.onOrderList(that.data.id);
            })
        } else {
            if (that.data.delivery_id == undefined) {
                wx.showToast({
                    title: '请选择快递公司',
                    icon: "none"
                })
            }
            if (that.data.result == undefined) {
                wx.showToast({
                    title: '请选择填写快递单号',
                    icon: "none"
                })
            }
        }

    }
})